﻿<UserControl x:Class="Microsoft.Forums.ForumsClient.Views.ForumFilterView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ForumsClient="clr-namespace:Microsoft.Forums.ForumsClient"
    xmlns:Views="clr-namespace:Microsoft.Forums.ForumsClient.Views"
    x:Name="FilterView"
    >
    <UserControl.Resources>
        <Views:IsStringEmptyToVisibilityConverter x:Key="IsStringEmptyToVisibility" />
        <Views:ObjectIsNullToVisibilityConverter x:Key="IsNullToVisibility" />

        <Style TargetType="{x:Type Views:TextImageToggleButton}">
            <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
            <Setter Property="Background" Value="{DynamicResource DefaultBackground}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Foreground" Value="{DynamicResource DefaultTextForeground}"/>
            <Setter Property="Margin" Value="5"/>
            <Setter Property="Height" Value="23"/>
            <Setter Property="Width" Value="Auto"/>
            <Setter Property="BorderThickness" Value="0.7"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Padding" Value="1"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Views:TextImageToggleButton}">
                        <Border x:Name="ToolBarButtonBorder" Width="Auto" Height="Auto" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"  BorderThickness="{TemplateBinding BorderThickness}">
                            <StackPanel x:Name="stackPanel" Width="Auto" Height="Auto" Orientation="Horizontal">
                                <Image Margin="2,0,2,0" VerticalAlignment="Center" Width="18" Height="18" 
				  Source="{TemplateBinding Source}"/>
                                <TextBlock HorizontalAlignment="Left" Margin="0,0,5,0" VerticalAlignment="Center" 
				  Text="{TemplateBinding Text}" TextWrapping="Wrap"/>
                            </StackPanel>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsKeyboardFocused" Value="true">
                                <Setter Property="BorderBrush" Value="{DynamicResource DefaultBorder}" 
                                    TargetName="ToolBarButtonBorder"/>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="BorderBrush" Value="{DynamicResource DefaultBorder}" TargetName="ToolBarButtonBorder"/>
                                <Setter Property="BorderThickness" Value="0.7" TargetName="ToolBarButtonBorder" />
                                <Setter Property="Background" TargetName="ToolBarButtonBorder" Value="{DynamicResource OnMouseOverBrush}"/>
                            </Trigger>
                            <Trigger Property="IsChecked" Value="true">
                                <Setter Property="Background" Value="{DynamicResource OnPressBackground}" TargetName="ToolBarButtonBorder"/>
                                <Setter Property="BorderBrush" Value="{DynamicResource DefaultBorder}" TargetName="ToolBarButtonBorder"/>
                                <Setter Property="BorderThickness" Value="0.7" TargetName="ToolBarButtonBorder" />
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Background" Value="{DynamicResource DisabledBackgroundBrush}" TargetName="ToolBarButtonBorder"/>
                                <Setter Property="BorderBrush" Value="{DynamicResource DisabledBorderBrush}" TargetName="ToolBarButtonBorder"/>
                                <Setter Property="Foreground" Value="{DynamicResource DisabledForegroundBrush}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <DockPanel LastChildFill="True">
        <Expander DockPanel.Dock="Top" x:Name="ForumExpander" 
                  DataContext="{Binding ElementName=FilterView, Path=ContainedView.DataContext}"
              Style="{DynamicResource ForumExpanderStyle}"
              IsExpanded="False" VerticalContentAlignment="Stretch" 
              BorderBrush="{DynamicResource DefaultBorder}" 
              Background="{DynamicResource DefaultBackground}"
              Visibility="{Binding Converter={StaticResource IsNullToVisibility}}"
              FontSize="11" FontWeight="Bold" 
              BorderThickness="0,0,0,0" HorizontalContentAlignment="Stretch" 
              Margin="0,0,0,0">
            <Expander.Header>
                <DockPanel HorizontalAlignment="Stretch" Margin="0,0,0,0" MinWidth="0" VerticalAlignment="Top" Width="Auto" Background="{x:Null}" LastChildFill="False" Height="20">
                    <Image DockPanel.Dock="Left" Margin="4,0,0,0" Width="16" Height="16" Stretch="Fill" Source="images\folder.ico" HorizontalAlignment="Left"/>
                    <TextBlock 
                               Text="{Binding}"
                               DockPanel.Dock="Left"  
                               Padding="0,0,0,0" 
                               TextWrapping="NoWrap" 
                               Margin="4,0,0,0" 
                               VerticalAlignment="Center" 
                               FontSize="16" FontWeight="Bold"    
                               HorizontalAlignment="Left" />
                    
                     <StackPanel Orientation="Horizontal" DockPanel.Dock="Right" >
                             <Label Content="Search"
                                   FontFamily="Veranda" 
                                   FontWeight="Bold"
                                   Height="23"
                                   VerticalAlignment="Center"/>
                            <TextBox x:Name="searchBox"  Width="120" Height="20" Text="{Binding Path=FilterSettings.SearchText, Mode=TwoWay, UpdateSourceTrigger=Explicit}" KeyDown="searchBox_KeyDown" />
                            <Button x:Name="searchButton" Click="searchButton_Click" Height="20" Width="20" Style="{DynamicResource SearchButton}"  >
                                <Button.Content>
                                    <Image x:Name="searchImage" Source="Images\search.ico" />
                                </Button.Content>
                            </Button>
                            <Button x:Name="cancelSearchButton" Style="{DynamicResource SearchButton}" 
                                    Visibility="{Binding Path=FilterSettings.SearchText, Converter={StaticResource IsStringEmptyToVisibility}}"  
                                    Click="cancelSearchButton_Click" Height="20" Width="20" >
                                <Button.Content>
                                    <Image x:Name="cancelImage" Source="Images\CancelSearch.ico" />
                                </Button.Content>
                            </Button>
                        </StackPanel>
                </DockPanel>
            </Expander.Header>

            <Border Width="Auto" Height="Auto" BorderBrush="{DynamicResource DefaultBorder}" BorderThickness="0,0.5,0,0">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="50*" />
                        <RowDefinition Height="50*" />
                    </Grid.RowDefinitions>
                    <StackPanel Grid.Row="1" Orientation="Horizontal" Height="50" Margin="5 5 5 5">
                        <Label Content="Filter By"
                                   FontFamily="Veranda" 
                                   FontWeight="Bold"
                                   Height="23"
                                   VerticalAlignment="Center"/>

                        <!-- Have directly put the comboitems here since this a simple list and bound to specific properties on the FilterSettings
                        -->
                        <ComboBox Height="23" Width="Auto" Margin="5">
                            <ComboBoxItem IsSelected="{Binding Path=FilterSettings.ResetFilterBy}" Selected="ApplyFilter">
                                <ComboBoxItem.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <Image Height="18" Width="18" Source="Images\AllThreads.png" />
                                        <TextBlock Text="Show All" Margin="0"/>
                                    </StackPanel>
                                </ComboBoxItem.Content>
                            </ComboBoxItem>
                            <ComboBoxItem IsSelected="{Binding Path=FilterSettings.IsCheckedUnanswered}" Selected="ApplyFilter">
                                <ComboBoxItem.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <Image Height="18" Width="18" Source="Images\NoReplies.png" />
                                        <TextBlock Text="Unanswered" Margin="0"/>
                                    </StackPanel>
                                </ComboBoxItem.Content>
                            </ComboBoxItem>
                            <ComboBoxItem IsSelected="{Binding Path=FilterSettings.IsCheckedAnswered}" Selected="ApplyFilter">
                                <ComboBoxItem.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <Image Height="18" Width="18" Source="Images\Answered.png" />
                                        <TextBlock Text="Answered" Margin="0"/>
                                    </StackPanel>
                                </ComboBoxItem.Content>
                            </ComboBoxItem>
                            <ComboBoxItem IsSelected="{Binding Path=FilterSettings.IsCheckedGeneralDiscussion}" Selected="ApplyFilter">
                                <ComboBoxItem.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <Image Height="18" Width="18" Source="Images\Comment.png" />
                                        <TextBlock Text="General Discussion" Margin="0"/>
                                    </StackPanel>
                                </ComboBoxItem.Content>
                            </ComboBoxItem>
                            <ComboBoxItem IsSelected="{Binding Path=FilterSettings.IsCheckedProposedAnswers}" Selected="ApplyFilter">
                                <ComboBoxItem.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <Image Height="18" Width="18" Source="Images\ProposedAnswer.png" />
                                        <TextBlock Text="Proposed Answers" Margin="0"/>
                                    </StackPanel>
                                </ComboBoxItem.Content>
                            </ComboBoxItem>
                        </ComboBox>
                        <Views:TextImageToggleButton IsChecked="{Binding Path=FilterSettings.IsCheckedHelpful}" Click="ApplyFilter" Source="Images\Helpful.png"  Text="Helpful" />
                        <Views:TextImageToggleButton IsChecked="{Binding Path=FilterSettings.IsCheckedNoReplies}" Click="ApplyFilter" Source="Images\NoReplies.png" Text="No Replies" />
                    </StackPanel>
                </Grid>
            </Border>
        </Expander>
        <ContentPresenter VerticalAlignment="Stretch" HorizontalAlignment="Stretch" x:Name="filterableView" />
    </DockPanel>
</UserControl>
